<?php 
require_once 'BaseMySQLDAO.php';
require_once dirname(__FILE__).DIRECTORY_SEPARATOR.'../Entity/Domain/Ps_payment_ccDomain.php';
class Ps_payment_ccDAO extends BaseMySQLDAO
{
	public function __construct($context) {
		parent::__construct($context, Ps_payment_ccDomain::$CollectionName);
	}

	public function create($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "INSERT INTO ps_payment_cc(id_payment_cc,id_order,id_currency,amount,transaction_id,card_number,card_brand,card_expiration,card_holder,date_add)
					VALUES	(
								".$obj->getId_payment_cc().",
								".$obj->getId_order().",
								".$obj->getId_currency().",
								".$obj->getAmount().",
								'".$obj->getTransaction_id()."',
								'".$obj->getCard_number()."',
								'".$obj->getCard_brand()."',
								'".$obj->getCard_expiration()."',
								'".$obj->getCard_holder()."',
								'".$obj->getDate_add()."'
							)";
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function deleteByOid($oid){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "DELETE FROM ps_payment_cc WHERE id_payment_cc=".$oid;
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function update($obj){
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "UPDATE ps_payment_cc
				SET
					ps_payment_cc.id_order = ".$obj->getId_order().",
					ps_payment_cc.id_currency = ".$obj->getId_currency().",
					ps_payment_cc.amount = ".$obj->getAmount().",
					ps_payment_cc.transaction_id = '".$obj->getTransaction_id()."',
					ps_payment_cc.card_number = '".$obj->getCard_number()."',
					ps_payment_cc.card_brand = '".$obj->getCard_brand()."',
					ps_payment_cc.card_expiration = '".$obj->getCard_expiration()."',
					ps_payment_cc.card_holder = '".$obj->getCard_holder()."',
					ps_payment_cc.date_add = '".$obj->getDate_add()."'
				 WHERE id_payment_cc=".$obj->getId_payment_cc();
		$this->getMySQLConnection()->mysqlData($inSQL);
		$this->getContext()->getDBTransaction()->closeTransaction();
	}

	public function findByOid($oid)
	{
		$ps_payment_ccDomain = null;
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM ps_payment_cc WHERE ps_payment_cc.id_payment_cc = ".$oid;
		$res = $this->getMySQLConnection()->mysqlOneRow($inSQL);
		if($res)
		{
			$ps_payment_ccDomain = new Ps_payment_ccDomain($res);
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $ps_payment_ccDomain;
	}

	public function findAll()
	{
		$ps_payment_ccDomainArr = array();
		$this->getContext()->getDBTransaction()->startTransaction();
		$inSQL = "SELECT * FROM ps_payment_cc";
		$res = $this->getMySQLConnection()->mysqlData($inSQL);
		if($res)
		{
			while ($data = mysql_fetch_assoc($res))
			{
				$ps_payment_ccDomain = new Ps_payment_ccDomain($data);
				$ps_payment_ccDomainArr[] = $ps_payment_ccDomain;
			}
		}
		$this->getContext()->getDBTransaction()->closeTransaction();
		return $ps_payment_ccDomain;
	}

}
?>